// "Copyright [2021] <Copyright Han>"
#ifndef CLUSTER_ROCE_ROUTING_ADAPTER_H_
#define CLUSTER_ROCE_ROUTING_ADAPTER_H_

#include <utility>
#include <vector>
#include <map>
#include <unordered_map>
#include "inet/custom/controlAdapter_m_m.h"
// #include "inet/node/inet/Router.h"
#include "cluster/basic/ai_sim.h"

namespace ai_sim {
// class TopoManager;
struct pair_hash3
{
    template<class T1, class T2>
    std::size_t operator() (const std::pair<T1, T2>& p) const
    {
        auto h1 = std::hash<T1>{}(p.first);
        auto h2 = std::hash<T2>{}(p.second);
        return h1 ^ h2;
    }
};

class RoutingAdapter : public omnetpp::cSimpleModule {
 private:
   //  TopoManager* topos;
   // record the map from outputGateId to IPaddress
    std::unordered_map<pair<int, int>, int, pair_hash3> IpAddressMap;
    // record the map from outputGateId to mask
    std::unordered_map<pair<int, int>, int, pair_hash3> NetmaskMap;
    // record the map from outputGateId to InterfaceID
    std::unordered_map<pair<int, int> , int, pair_hash3> outputGateInterfaceMap;
    // record the map from inputGateId to InterfaceID
    std::unordered_map<pair<int, int> , int, pair_hash3> inputGateInterfaceMap;
    // record the map from outputGateIndex to outputGateId
    std::unordered_map<std::pair<int,int>, int, pair_hash3> outportIndexMap;
    // record the map from outputGateIndex to inportGateId
    //std::unordered_map<std::pair<int,int>, int, pair_hash3> inportIndexMap;
    // 记录来自于controller用于切分小clos的信息
    std::unordered_map<unsigned int, vector<int>> validPortMap;
 public:
    void getACL(vector<ACLSingleEntry>& , RouteVec, int);
    // send the route to one router
   //  void sendSingleFlow(int switch_ID, int SourceAddress,
   //    int DestAddress, int NextHopAddress,
   //    int DestPort, int interfaceID, int priority, int protocolID);


 protected:
    // 接受来自于Ipv4NetworkConfigurator/controller的信息
    void handleMessage(omnetpp::cMessage *msg) override;
    vector<int> valid_port_list;
};

}   // namespace inet
#endif  // CLUSTER_ROCE_ROUTING_ADAPTER_H_
